using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FernUniHagen.CompilerExtension.DataStructures;
using Roslyn.Compilers.Common;
using Roslyn.Compilers.CSharp;
using FernUniHagen.CompilerExtension.Interfaces;

namespace FernUniHagen.CompilerExtension.Adaptor
{
    public class PropertyDeclarationAdaptor : DeclarationBase, IDeclaration<CommonSyntaxNode>
    {
        #region members
        PropertyDeclarationSyntax _propertyDeclaration;
        #endregion

        #region constructor

        public PropertyDeclarationAdaptor(ISemanticModel model, PropertyDeclarationSyntax node) 
        {
            this.SemanticModel = model;

            _propertyDeclaration = node;
            Initialize();
        }
        #endregion



        /// <summary>
        /// Returns the name of the variable
        /// </summary>
        /// <returns></returns>
        public override string GetName()
        {
            return _propertyDeclaration.Identifier.ToString();
        }
        public override TypeSyntax GetTypeSyntax()
        {
            return _propertyDeclaration.Type;
        }

        public override SyntaxList<AttributeListSyntax> GetAttributes()
        {
            return _propertyDeclaration.AttributeLists;
        }

        public override StatementReplacement<CommonSyntaxNode> ConvertToMutiplicity(string newVariableName)
        {

            var newIdentifier = Syntax.ParseToken(newVariableName);

            if (MultiplicityType == AttributeType.Any)
            {
                return new StatementReplacement<CommonSyntaxNode>(_propertyDeclaration, _propertyDeclaration.WithType(GenericName).WithIdentifier(newIdentifier));
            }
            return new StatementReplacement<CommonSyntaxNode>(_propertyDeclaration, _propertyDeclaration.WithIdentifier(newIdentifier));
        }
    }
}
